const athletesService = require('../service/athletesService')
class AthletesController {
  async getAthleteList(ctx, next) {
    const { pagenum, pagesize, athleteName, telephone, sex, collegeId } = ctx.request.body
    const res = await athletesService.getAthleteList(pagenum, pagesize,athleteName,telephone,sex,collegeId)
    ctx.body = {
      data: {
        pagenum,
        ...res
      },
      meta: {
        msg: '获取成功',
        status:200
      }
    }
  }
  async removeAthlete(ctx, next) {
    const {id} = ctx.params
    await athletesService.removeAthlete(id)
    ctx.body = {
      meta: {
        msg:'删除成功'
      }
    }
  }
  async updateAthlete(ctx, next) {
    const { id } = ctx.params
    const { athleteName, telephone, sex, collegeId } = ctx.request.body
    await athletesService.updateAthlete(athleteName, telephone, sex, collegeId, id)
    ctx.body = {
      meta: {
        msg:'success'
      }
    }
  }
  async createAthlete(ctx, next) {
    const { athleteName, telephone, sex, collegeId, userId } = ctx.request.body 
    console.log(athleteName, telephone, sex, collegeId,userId);
    await athletesService.createAthlete(athleteName, telephone, sex, collegeId,userId )
    ctx.body = {
      meta: {
        msg:"success"
      }
    }
  }
  async getAthleteByUserId(ctx, next) {
    const { id } = ctx.params 
    const res = await athletesService.getAthlete(id)
    ctx.body = {
      data:res[0]
    }
  }
}
module.exports = new AthletesController()